package com.yupi.maker.cli.command;

import cn.hutool.core.bean.BeanUtil;
import com.yupi.maker.generator.MainGenerator;
import com.yupi.maker.model.MainTemplateConfig;
import freemarker.template.TemplateException;
import lombok.Data;
import picocli.CommandLine;

import java.io.IOException;
import java.util.concurrent.Callable;

/**
 * @version 1.0
 * @Author moresuo
 * @Date 2024/9/9 16:57
 * @注释 生成代码命令
 */
@CommandLine.Command(name="generator",mixinStandardHelpOptions = true)
@Data
public class GeneratorCommand implements Callable<Integer> {
    @CommandLine.Option(names={"-a","--author"},description = {"作者信息"},arity="0..1",interactive = true,echo = true)//当使用jar包运行时默认不会回显输入的参数，要将echo设置为true才会回显
    private String author;//作者信息
    @CommandLine.Option(names={"-o","--outputText"},description = {"输出文本"},arity="0..1",interactive = true,echo = true)
    private String outputText;//输出信息
    @CommandLine.Option(names={"-l","--loop"},description = {"是否循环"},arity="0..1",interactive = true,echo = true)
    private boolean loop;//是否循环

    @Override
    public Integer call() throws TemplateException, IOException {
        MainTemplateConfig mainTemplateConfig = new MainTemplateConfig();
        //私有属性必须提供get和set方法才能复制，所以要加一个@Data注解
        BeanUtil.copyProperties(this,mainTemplateConfig);//属性一致可以复制
        System.out.println("配置信息："+mainTemplateConfig);
        MainGenerator.doGenerate(mainTemplateConfig);
        return 0;
    }
}
